home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_074 / tdebug / tdebug.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  251 lines

  1.  
  2. /*
  3.  *  TDEBUG.C
  4.  *
  5.  *  (C)Copyright 1987 Matthew Dillon, All Rights Reserved
  6.  *  FreeWare.  May be distributed for non-profit only.
  7.  *
  8.  *  Debug any device .. usually trackdisk.device
  9.  *
  10.  *  AZTEC USERS:   MUST COMPILE  +CDL and LINK WITH THE LARGE EVERYTHING
  11.  *  LIBRARY!!!! (cl32.lib).  NOTE: This source expects all the amiga
  12.  *  symbols to be preloaded.  NOTE: There are some function calls in this
  13.  *  source which you don't have... the functions should be obvious and
  14.  *  easy to implement.
  15.  *
  16.  *  Sorry, no support for lattice.  A smart programmable will be able to
  17.  *  split the assembly file and do all the right #includes.
  18.  *
  19.  */
  20.  
  21. #define FIFO    struct _FIFO
  22.  
  23. typedef struct ExecBase EB;
  24. typedef struct List    LIST;
  25. typedef struct Node    NODE;
  26. typedef struct IOStdReq STD;
  27. typedef struct Task    TASK;
  28.  
  29. FIFO {
  30.     FIFO    *next;        /* next element */
  31.     STD     std;        /* IO request   */
  32. };
  33.  
  34. extern EB *SysBase;
  35. extern NODE *findlist();
  36. extern TASK *FindTask();
  37. extern char *AllocMem();
  38.  
  39. FIFO *Base, **Lnext = &Base;
  40.  
  41. NODE *Nodearray[64];
  42.  
  43. NODE *Ntrack;
  44. NODE *Nasdg;
  45.  
  46. TASK *Mastertask;
  47. long Operations;        /* # operations monitored    */
  48. long Mask, Signum;
  49.  
  50. char *Stdname[] = {
  51.     "INVALID", "RESET", "READ", "WRITE", "UPDATE", "CLEAR", "STOP",
  52.     "START", "FLUSH"
  53. };
  54.  
  55. main(ac, av)
  56. char *av[];
  57. {
  58.     register FIFO *fifo;
  59.     register long result;
  60.  
  61.     disablebreak();
  62.     Mastertask = FindTask(0);
  63.     Signum = AllocSignal(-1);
  64.     Mask = 1 << Signum;
  65.     loadnodearray(ac, av);    /* which devices to intercept?    */
  66.  
  67.     overidevector(1);
  68.     puts ("Now intercepting all DoIO() and SendIO() operations");
  69.     puts ("");
  70.     puts ("Device__         Cmd_ Len_____");
  71.     SetSignal(0, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D);
  72.     for (;;) {
  73.     result = Wait(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|Mask);
  74.     if (result & (SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D))
  75.         break;
  76.     while (Base) {
  77.         long block, cmd;
  78.         char ext;
  79.  
  80.         Forbid();
  81.         fifo = Base;
  82.         Base = Base->next;
  83.         if (Base == NULL)
  84.         Lnext = &Base;
  85.         Permit();
  86.         printf ("%16s ", fifo->std.io_Device->dd_Library.lib_Node.ln_Name);
  87.         cmd = fifo->std.io_Command;
  88.         ext = ' ';
  89.         if (cmd & TDF_EXTCOM) {
  90.         cmd &= ~TDF_EXTCOM;
  91.         ext = 'E';
  92.         }
  93.         if (fifo->std.io_Command < CMD_NONSTD)
  94.         printf ("%lc%-7s ", ext, Stdname[fifo->std.io_Command]);
  95.         else
  96.         printf (" NON+%lc%-2ld ", ext, fifo->std.io_Command - CMD_NONSTD);
  97.         printf ("%-8ld %-8ld ", fifo->std.io_Length, fifo->std.io_Offset);
  98.         if (fifo->std.io_Device == Ntrack || fifo->std.io_Device == Nasdg) {
  99.         block = fifo->std.io_Offset / 512;
  100.         printf ("Blk#: %-5ld ", block);
  101.         printf ("(Trk %2ld  Cyl %2ld) ", block/22, (block/11)&1);
  102.         }
  103.         puts("");
  104.         FreeMem(fifo, sizeof(*fifo));
  105.     }
  106.     }
  107.     puts ("Restoring intercept vector");
  108.     overidevector(0);
  109.     Delay(50);
  110.     while (Base) {
  111.     fifo = Base->next;
  112.     FreeMem(Base, sizeof(*Base));
  113.     Base = fifo;
  114.     }
  115.     FreeSignal(Signum);
  116.     printf ("%ld operations monitored\n", Operations);
  117. }
  118.  
  119.  
  120. loadnodearray(ac, av)
  121. char *av[];
  122. {
  123.     register int i;
  124.     register int j;
  125.     register NODE *node;
  126.     register LIST *list = &SysBase->DeviceList;
  127.  
  128.     Ntrack = findlist(list, "trackdisk.device");
  129.     Nasdg  = findlist(list, "asdg.vdisk.device");
  130.     if (ac == 1) {
  131.     puts ("TDEBUG V1.00  By Matthew Dillon");
  132.     puts ("(C)Copyright 1987 Mathew Dillon, All Rights Reserved");
  133.     puts ("CTRL-C, CTRL-D, or BREAK to terminate");
  134.     puts ("");
  135.     puts ("tdebug device device...");
  136.     puts ("tdebug trackdisk.device");
  137.     puts ("");
  138.     showlist(list);
  139.     puts ("");
  140.     exit(1);
  141.     }
  142.     for (i = 1, j = 0; av[i]; ++i) {
  143.     node = findlist(list, av[i]);
  144.     if (!node)
  145.         printf ("Unable to find: %s\n", av[i]);
  146.     else
  147.         Nodearray[j++] = node;
  148.     }
  149. }
  150.  
  151.  
  152. NODE *
  153. findlist(list, name)
  154. LIST *list;
  155. char *name;
  156. {
  157.     register NODE *node;
  158.  
  159.     for (node = list->lh_Head; node != &list->lh_Tail; node = node->ln_Succ) {
  160.     if (strcmp(name, node->ln_Name) == 0)
  161.         return(node);
  162.     }
  163.     return(NULL);
  164. }
  165.  
  166. showlist(list)
  167. LIST *list;
  168. {
  169.     register NODE *node;
  170.  
  171.     for (node=list->lh_Head; node != &list->lh_Tail; node=node->ln_Succ) {
  172.     puts(node->ln_Name);
  173.     }
  174. }
  175.  
  176.  
  177.  
  178. static long oldsendvec;
  179. static long olddovec;
  180.  
  181. overidevector(n)
  182. {
  183.     extern char LVODoIO;
  184.     extern char LVOSendIO;
  185.     extern int newsendio(), newdoio();
  186.  
  187.     Forbid();
  188.     if (n) {
  189.     oldsendvec = SetFunction(SysBase, &LVOSendIO, newsendio);
  190.     olddovec =   SetFunction(SysBase, &LVODoIO,   newdoio);
  191.     } else {
  192.     SetFunction(SysBase, &LVOSendIO, oldsendvec);
  193.     SetFunction(SysBase, &LVODoIO,     olddovec);
  194.     }
  195.     Permit();
  196. }
  197.  
  198. /*
  199.  *  NOTE!!! Since BeginIO is the basis for the entire operating system,
  200.  *  we cannot do anything inside this routine that would ever use it.
  201.  */
  202.  
  203. myio(ioreq)
  204. register STD *ioreq;
  205. {
  206.     register FIFO *fifo;
  207.     register int i;
  208.  
  209.     Forbid();
  210.     for (i = 0; Nodearray[i]; ++i) {
  211.     if (Nodearray[i] == ioreq->io_Device)
  212.         break;
  213.     }
  214.     if (Nodearray[i]) {
  215.     if (fifo = (FIFO *)AllocMem(sizeof(*fifo), 0)) {
  216.         *Lnext = fifo;
  217.         Lnext = &fifo->next;
  218.         fifo->next = NULL;
  219.         fifo->std = *ioreq;
  220.     }
  221.     ++Operations;
  222.     Signal(Mastertask, Mask);
  223.     }
  224.     Permit();
  225. }
  226.  
  227. #asm
  228.  
  229. _newsendio:
  230.         movem.l D0-D7/A0-A6,-(sp)   ;save regs
  231.         move.l    A1,-(sp)        ;the io request
  232.         jsr    _myio            ;call my intercept routine
  233.         addq.l    #4,sp
  234.         movem.l (sp)+,D0-D7/A0-A6   ;restore regs
  235.         move.l    _oldsendvec,A0        ;A0 not used by SendIO
  236.         jsr (A0)
  237.         rts
  238.  
  239. _newdoio:
  240.         movem.l D0-D7/A0-A6,-(sp)   ;save regs
  241.         move.l    A1,-(sp)        ;the io request
  242.         jsr    _myio            ;call my intercept routine
  243.         addq.l    #4,sp
  244.         movem.l (sp)+,D0-D7/A0-A6   ;restore regs
  245.         move.l    _olddovec,A0      ;A0 not used by SendIO
  246.         jsr (A0)
  247.         rts
  248.  
  249. #endasm
  250.  
  251.